/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gc.cscott.verify.common;

import com.gc.cscott.verify.JavaTaskOutputVerifier;
import com.gc.cscott.verify.OutputVerifier.VerifiedOutput;
import com.google.common.base.Preconditions;

/**
 *
 * @author stukalin_ap
 */
public class EqualsIgnoreLineEndings implements JavaTaskOutputVerifier {

    private String cleanUp(String value) {
        return value.replace("\r", "\n").replace("\n\n", "\n").replaceAll("\\s+$", "");
    }

    public VerifiedOutput verify(String inputText, String outputText, String validationHintText) {
        Preconditions.checkNotNull(inputText);
        Preconditions.checkNotNull(outputText);
        Preconditions.checkNotNull(validationHintText);

        inputText = cleanUp(inputText);
        outputText = cleanUp(outputText);
        validationHintText = cleanUp(validationHintText);

        if (outputText.equals(validationHintText)){
            return VerifiedOutput.outputIsCorrect();
        } else {
            return VerifiedOutput.outputIsWrong("Presented '"+outputText.trim()+"' but expected '"+validationHintText.trim()+"'");
        }
    }

//    public static void main(String[] args) {
//        JavaTaskOutputVerifier vf = new EqualsIgnoreLineEndings();
//
//        System.out.println(vf.verify("aa", "asdf\ndf\nr", "asdf\ndf\nr").getOutputStatus());
//    }
}
